﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FreshClickMedia.Web.UI.WebControls;

namespace Yu.Cms.Web.UserCtrl.Default
{
    public partial class GuestBook : BaseCtrl
    {
        protected int RecordCount = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.OnStar();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected void OnStar()
        {
            this.Pager.PageSize = 12;
            this.BindrptBook();
            //文章标题
            (base.Page.Master.FindControl("lblTitle") as Literal).Text = "留言本";
        }

        

        /// <summary>
        /// 绑定留言数据
        /// 只显示审核通过的留言
        /// </summary>
        protected void BindrptBook()
        {
            int PageIndex = Pager.CurrentPageIndex;
            int PageSize = Pager.PageSize;            
            rptBook.DataSource = bllBook.GetPubList(PageIndex, PageSize, out RecordCount);
            rptBook.DataBind();
            Pager.RecordCount = RecordCount;
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            this.BindrptBook();
        }

        protected void rptBook_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Gravatar Gravatar2 = (Gravatar)e.Item.FindControl("Gravatar2");
                Gravatar2.Email = siteModel.SiteEmail;
                Literal lblReply = (Literal)e.Item.FindControl("lblReply");
                lblReply.Text = "admin";  //暂定
             
                Literal lblReContent = (Literal)e.Item.FindControl("lblReContent");
               
                Panel pReply = (Panel)e.Item.FindControl("pReply");

                if (!string.IsNullOrEmpty(lblReContent.Text))
                {
                    pReply.Visible = true;
                }
                else
                {
                    pReply.Visible = false;
                }
            }

        }
    }
}